Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  What does fun2() do in general?int fun(int x,... Start Learning for Free
What does fun2() do in general?
int fun(int x, int y)
{
if (y == 0)   return 0;
return (x + fun(x, y-1));
}
int fun2(int a, int b)
{
if (b == 0) return 1;
return fun(a, fun2(a, b-1));
}
  • a)
    x*y
  • b)
    x+x*y
  • c)
    xy
  • d)
    yx
Correct answer is option 'C'. Can you explain this answer?
Most Upvoted Answer
What does fun2() do in general?int fun(int x, int y){if (y == 0) retu...
Explanation:

The given code defines two functions - fun and fun2.

Function fun:
- It takes two integer inputs x and y.
- If y is equal to 0, it returns 0.
- Otherwise, it recursively calls itself with x and y-1 as inputs and returns x multiplied by the result of the recursive call.

Function fun2:
- It takes two integer inputs a and b.
- If b is equal to 0, it returns 1.
- Otherwise, it recursively calls itself with a and b-1 as inputs and passes the result of the recursive call to the function fun with a and the recursive result as inputs. It returns the result of the fun function call.

Now, let's understand what happens when we call the function fun2 with inputs a=2 and b=3:

- fun2(2,3) is called.
- Since b is not equal to 0, it calls itself with a=2 and b-1=2 as inputs.
- fun2(2,2) is called.
- Since b is not equal to 0, it calls itself again with a=2 and b-1=1 as inputs.
- fun2(2,1) is called.
- Since b is not equal to 0, it calls itself again with a=2 and b-1=0 as inputs.
- fun2(2,0) is called.
- Since b is now equal to 0, it returns 1.
- The result of the previous recursive call is passed to the fun function with a=2.
- fun(2,1) is called.
- It calls itself with x=2 and y-1=0 as inputs.
- Since y is now equal to 0, it returns 0.
- The result of the previous fun call is multiplied by x=2 and returned.
- The final result of fun2(2,3) is 2 multiplied by the result of fun(2,2), which is 4.
- Therefore, the correct option is C) xy, which is equivalent to 2*3=6.

In summary:
- Function fun multiplies x by y recursively.
- Function fun2 calls fun recursively and passes the result to the next recursive call.
- When we call fun2(2,3), it returns 2 multiplied by the result of fun(2,2), which is 4.
- Therefore, the answer is C) xy, which is equivalent to 2*3=6.
Free Test
Community Answer
What does fun2() do in general?int fun(int x, int y){if (y == 0) retu...
The function multiplies x to itself y times which is xy.
Explore Courses for Computer Science Engineering (CSE) exam
Question Description
What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer?.
Solutions for What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What does fun2() do in general?int fun(int x, int y){if (y == 0) return 0;return (x + fun(x, y-1));}int fun2(int a, int b){if (b == 0) return 1;return fun(a, fun2(a, b-1));}a)x*yb)x+x*yc)xyd)yxCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev